﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _06_委托练习
{
    public partial class Frm_P2PMove : Form
    {
        public Frm_P2PMove(int x,int y,Action<bool> action)
        {
            InitializeComponent();

            //初始化位置
            this.textBox1.Text = x.ToString();
            this.textBox2.Text = y.ToString();

            //绑定事件
            this.button1.Click += (sender, e) =>
            {
                //获取目标位置
                int X = int.Parse(this.textBox1.Text);
                int Y = int.Parse(this.textBox2.Text);
                //调用委托
                MainForm.SetButtonLocation(X, Y);
            };

            //关闭窗体-响应事件
            this.FormClosed += (sender, e) => action(true);


        }

        public void SetButtonLocation(int x, int y)
        {
            this.textBox1.Text = x.ToString();
            this.textBox2.Text = y.ToString();
        }

    }
}
